(ns utilities.DBMain-test
	(:use clojure.test utilities.DBMain))

	
(deftest reading-test
	"tests the method reading from the class DBMain"
	(is (= {:owner "", :date "2005/03/23",
		:rate "$210.00", :smoking "N", :size "2", :location "Smallville", 
		:name "Excelsior", :deleted false} (reading 0)))
		(is (= {:owner "", :date "2004/11/15",
		:rate "$150.00", :smoking "Y", :size "4", :location "Smallville", 
		:name "Splendide", :deleted false} (reading 1)))
	(is (= nil (reading 50)))
	(is (= nil (reading "a")))
)



(deftest update-test
	"tests the method update from the class DBMain"
	(is (= "updated done" (update 4 {:owner "", :date "2005/03/23", :rate "$210.00", :smoking "N", :size "2", :location "Smallville", :name "Excelsior", :deleted "true"})))
	(is (= "updated done" (update 2 {:owner "", :date "2005/03/23",
		:rate "$210.00", :smoking "N", :size "2", :location "Smallville", 
	:name "Excelsior", :deleted "true"}))) 
	(is (= "updated done" (update  3 {:owner "", :date "2005/03/23",
		:rate "$210.00", :smoking "N", :size "2", :location "Smallville", 
	:name "Excelsior", :deleted "true"})))
)	



(deftest update-tuple-test 
	"tests the method update-tuple from the class DBMain"
		(is (= nil (update-tuple 7 {:owner "gusgus"})))
		(is (= nil (update-tuple 8 {:owner "yoyo", :date "2005/11/2004"})))
		(is (= nil (update-tuple 9 {:owner "", :date "2005/03/23", :rate "$210.00"})))
		(is (= nil (update-tuple 10 {:owner "", :date "2005/03/23",
				:rate "$210.00", :smoking "N", :size "2", :location "Smallville", 
		:name "Excelsior", :deleted "false"})))
)


(deftest delete-test
	"tests the method delete from the class DBMain"
	(is (= nil (delete 10)))
	(is (thrown? java.lang.Exception (delete "gato")))
)


(deftest takeoff-$-test
	"tests the method takeoff-$ from the class DBMain"
	(is (= {:rate "100.00"} (takeoff-$ {:rate "$100.00"})))
	(is (= {:owner "betito", :rate "100.00"} (takeoff-$ {:owner "betito", :rate "$100.00"})))
	(is (= {:smoking "N", :owner "betito", :rate "100.00"} (takeoff-$ {:smoking "N", :owner "betito", :rate "$100.00"})))
	(is (= {} (takeoff-$ {})))
(is (= {:owner "betito"} (takeoff-$ {:owner "betito"}))))


(deftest add-extension-test
	"tests the method add-extension from the class DBMain"
	(is (= {:owner "betito.*"} (add-extension {:owner "betito"})))
	(is (= {:owner "betito.*", :rate "100.00.*"} (add-extension {:owner "betito", :rate "$100.00"})))
	(is (= {:smoking "N.*", :owner "betito.*", :rate "100.00.*"} 
		(add-extension {:smoking "N", :owner "betito", :rate "$100.00"})))
(is (= {} (add-extension {}))))


(deftest matches-test
	"tests the method matches from the class DBMain"
	(is (= true (matches {} {})))
	(is (= true (matches  {:owner "betito"} {:owner "b"})))
	(is (= false (matches  {:owner "betito"} {:owner "c"})))
	(is (= true (matches  {:rate "$100"} {:rate "$100"})))
	(is (= true (matches  {:rate "$100", :owner "betito"} {:rate "$100", :owner "b"})))
(is (= false (matches  {:rate "$100", :owner "b"} {:rate "$100", :owner "betito"}))))


(deftest find-registers-test
	"tests the method find-registers from the class DBMain"
(is (list? '(findregisters {:location "Smallville"})))
(is (list? '(findregisters {:location "jajaja"})))
(is (list? '(findregisters {:location "Smallville", :owner "Clark kent"})))
(is (list? '(findregisters {:name "Excelsior", :deleted "false"}))))

; (deftest read_all-test
	; "tests the method read_all from the class DBMain"
	; (is (= [30 [["name" 64] ["location" 64] ["size" 4] ["smoking" 1] ["rate" 8]["date" 10]["owner" 8]]]
; (read_all (java.io.RandomAccessFile. "db-1x2.db" "rw")))))
	; 
; 
; 
; (deftest create-test
	; "tests the method create from the class DBMain"
	; (is (= (30 (create {:owner "gusgus", :date "2005/03/23", :rate "$210.00", :smoking "N", 
; :size "2", :location "granville", :name "Excelsior", :deleted "true"})))) 

	;(run-tests)
